package com.zone.gateway.core.session.impl;

import com.zone.gateway.core.bind.IGenericReference;
import com.zone.gateway.core.session.Configuration;
import com.zone.gateway.core.session.GatewaySession;
import com.zone.gateway.core.executor.Executor;
import com.zone.gateway.core.mapping.HttpStatement;

import java.lang.reflect.Method;
import java.util.Map;

/**
 * @author: zongzi
 * @description: 默认的网关session
 * @date: 2025/4/18
 */
public class DefaultGatewaySession implements GatewaySession {

    private final Configuration configuration;
    private final String uri;

    private final Executor executor;

    public DefaultGatewaySession(Configuration configuration, String uri, Executor executor) {
        this.configuration = configuration;
        this.uri = uri;
        this.executor = executor;
    }

    @Override
    public Object get(Method method, Map<String, Object> args) {
        HttpStatement httpStatement = configuration.getHttpStatement(uri);
        // 获取返回结果
        return executor.execute(httpStatement, args);
    }

    @Override
    public Object post(Method method, Map<String, Object> args) {
        return this.get(method, args);
    }

    @Override
    public IGenericReference getMapped() {
        return configuration.getMapped(uri, this);
    }

    @Override
    public Configuration getConfiguration() {
        return configuration;
    }
}
